﻿using System;
using System.Web.UI.WebControls;
using MedicWeb.MedicService;

namespace MedicWeb.forms {
    public partial class SpecialityList : SessionPage {
        protected void Page_Load(object sender, EventArgs e) {
            var ms = new MainService();

            string value = hfSpecNumber.Value;
            if (!string.IsNullOrEmpty(value)) {
                string[] split = value.Split('=');
                int id = Convert.ToInt32(split[0]);
                int number = Convert.ToInt32(split[1]);
                Speciality speciality = ms.LoadSpeciality(GetSession(), id);
                speciality.Number = number;
                ms.SaveSpeciality(GetSession(), speciality);
                hfSpecNumber.Value = "";
            }
            Speciality[] specialityList = ms.GetSpecialityList(GetSession(), false);
            foreach (var speciality in specialityList) {
                var row = new TableRow();
                var cellUpDown = new TableCell();
                var cellEdit = new TableCell();
                var cellTitle = new TableCell();
                
                cellUpDown.Width = 24;
                cellEdit.Width = 24;

                cellUpDown.Controls.Add(new HyperLink() {
                    CssClass = "updown"
                });
                cellEdit.Controls.Add(new HyperLink() {
                    CssClass = "edit modal",
                    NavigateUrl = ResolveUrl("~/forms/Editors/Directory/SpecialityEdit.aspx?id="+speciality.Id)
                });
                cellTitle.Text = speciality.Title;
                
                row.Cells.Add(cellUpDown);
                row.Cells.Add(cellEdit);
                row.Cells.Add(createDeleteCell(speciality));
                row.Cells.Add(cellTitle);
                tblSpeciality.Rows.Add(row);
            }
        }
    }
}
